<?php
include '../dbconnect.php';

?>
<!DOCTYPE html>
<html lang="zh">
  <head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- The above 3 meta tags *must* come first in the head; any other head content must come *after* these tags -->
    <!-- <meta name="description" content=""> -->
    <!-- <meta name="author" content=""> -->
    <!-- <link rel="icon" href="../../favicon.ico"> -->

    <title>Employer Manager</title>

    <!-- Bootstrap core CSS -->
    <link href="./css/bootstrap.min.css" rel="stylesheet">
		
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!-- <link href="../../assets/css/ie10-viewport-bug-workaround.css" rel="stylesheet"> -->

    <!-- Custom styles for this template -->
    <link href="./css/navbar-fixed-top.css" rel="stylesheet">

    <!-- Just for debugging purposes. Don t actually copy these 2 lines! -->
    <!--[if lt IE 9]><script src="../../assets/js/ie8-responsive-file-warning.js"></script><![endif]-->
    <!-- <script src="../../assets/js/ie-emulation-modes-warning.js"></script> -->

    <!-- HTML5 shim and Respond.js for IE8 support of HTML5 elements and media queries -->
    <!--[if lt IE 9]>
      <script src="https://oss.maxcdn.com/html5shiv/3.7.3/html5shiv.min.js"></script>
      <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->

    <script src="../js/jquery.js"></script>
      <script src="../js/jquery-3.4.1.min.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <!-- IE10 viewport hack for Surface/desktop Windows 8 bug -->
    <!-- <script src="../../assets/js/ie10-viewport-bug-workaround.js"></script> -->
	<script src="https://code.jquery.com/jquery-3.6.0.min.js"></script>

  </head>

  <body>

    <!-- Fixed navbar -->
    <?php include 'adminHeader.php'; ?>
    <div class="container">
      <!-- Main component for a primary marketing message or call to action -->
      <div class="jumbotron">
        <h1>Employee Management</h1>
        <p>This is the user management section, where you can perform Create, Read, Update, Delete operations on users.</p>
      </div>
		<table class="table ">
        <a href="addEmployee.php" class="btn btn-success">add employee</a>
        <thead>
          <tr>
            <th>id</th>
            <th>username</th>
            <th>password</th>
            <th>email</th>
			<th>admin operate</th>
          </tr>
        </thead>
        <tbody>
      <?php
      $sql = "SELECT * FROM staff where IS_DELETE = 0";
      $result = $conn->query($sql);
      if ($result->num_rows > 0) {
        while($row = $result->fetch_assoc()) {
          ?>

    <tr>
      <td><?php echo $row["S_ID"]; ?></td>
      <td><?php echo $row["S_Username"]; ?></td>
      <td><?php echo $row["S_Password"]; ?></td>
      <td><?php echo $row["S_Email"]; ?></td>
      <td>
        <a href="javascript:void(0);" class="btn btn-primary" onclick="editEmployee('<?php echo htmlspecialchars($row['S_ID']); ?>')">edit employee</a>
		<button class="btn btn-danger" onclick="deluser('<?php echo htmlspecialchars($row['S_ID']); ?>');">del employee</button></td>
    </tr>

          <?php

        }
      } else {
        echo "0 result";
      }
      $conn->close();
      ?>
    </tbody>
  </table>


    </div> <!-- /container -->
<script type="text/javascript">

	function editEmployee(uid) {
		if (confirm('are you sure edit？')) {
			window.location.href = "editEmployee.php?uid=" + uid;
		}
	}
	function deluser(uid) {
		if (confirm('are you sure？')) {
			$.post("delEmployee.php", {
				uid: uid
			}, function(data, status) {
				if (data === "1") {
					alert('del success！');
					setTimeout(function() {
						location.href = "employeeList.php";
					}, 300);
				} else {
					alert('del fail！');
				}
			});
		}
	}
</script>
  </body>

</html>
